package name.wilbur.course.db.bigone.dao;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.List;

import javax.sql.DataSource;

import name.wilbur.course.db.bigone.model.BaseDBModel;

import org.apache.log4j.Logger;



public interface IDAO {
	/**
	 * Insert a record in the corresponding table.
	 * And set the PK attribute of dbentity.
	 */
	public boolean create(BaseDBModel dbentity);
	
	/**
	 * Update a record by primary key.
	 * @param pk Primary key of the record to update.
	 */
	public boolean update(BaseDBModel dbentity);
	
	/**
	 * Delete a record by primary key.
	 * @param pk the primary key.
	 */
	public boolean delete(int pk);
	
	/**
	 * Find a record by primary key.
	 * @param pk primary key of the record to select
	 * @return Corresponding entity object array of the record. 
	 */
	public BaseDBModel findByPK(int pk);
	
	public List<BaseDBModel> findAll();
	public List<BaseDBModel> find(String sql);
	
	public void create(BaseDBModel[] dbentity);
	public void update(BaseDBModel[] dbentity);
	public void delete(BaseDBModel[] dbentity);
	// be cautious
	public void clearDB();
	/**
	 * Execute a selecting sql script.
	 */
	public void query(String sql);
	/**
	 * MUST be paired with closeConnection()
	 */
	public void queryNotClose(String sql) throws SQLException;
	/**
	 * Close connection.
	 */
	public void closeConnection();
	
	public ResultSet getResultSet();
	
	public void setDataSource(DataSource ds);
	public DataSource getDataSource();
	
	/**
	 * Get logger.
	 */
	public Logger log();
}
